import json
import os

# 同步下载状态
types = [{"value": "1", "desc": "课本"}, {"value": "3", "desc": "课外读物"}]
useListFileName = "use_bookList_{}.json"
# bookDetail_{publishingId}_{bookId}.json
useBookFilePath = "use_{}/bookDetail_{}_{}.json";

for ind, type in enumerate(types):
    listNameFile = open(useListFileName.format(type['value']), mode='r')
    list = json.loads(listNameFile.read())
    listNameFile.close()
    for ind, book in enumerate(list['data']):
        if os.path.exists(useBookFilePath.format(type['value'], book['publishing_id'], book['id'])):
            book['is_download'] = 1
            print("bookId:" + book['id'] + "下载状态已经更新")
    print(json.dumps(list, ensure_ascii=False), file=open(useListFileName.format(type['value']), mode="w"))
